import Vue from "vue";
import App from "./App.vue";
import { router } from "./router/index";
import store from "./store/index";
import "amfe-flexible"; // 引入flexible
import Antd from "ant-design-vue";
import "ant-design-vue/dist/antd.css";
import "babel-polyfill";
import { apiList } from "./api/apiList";
import originalAxios from "axios";
import config from './config/index';
import Vconsole from 'vconsole';
let vConsole = new Vconsole();

//设置为 false 以阻止 vue 在启动时生成生产提示
Vue.config.productionTip = false;
Vue.use(Antd);
Vue.use(vConsole);

const axios = originalAxios.create({
	baseURL: config.baseURL,
	headers: {
		common: {
			Authorization: store.state.token
		}
	}
});
Vue.use({
	install (vue) {
		vue.prototype.$axios = axios;
		vue.prototype.$apiList = apiList;
	}
});
router.beforeEach((to, from, next) => {
	if (to.meta.token) {
		if (!store.state.token) {
			router.push("/login");
		} else {
			next();
		}
	} else {
		next();
	}
});
new Vue({
	router,
	store,
	axios,
	render: h => h(App)
}).$mount("#app");
